package com.bocloud.cmp.driver.convertor.os;

import java.util.List;

import org.openstack4j.model.storage.block.VolumeSnapshot;

import com.bocloud.cmp.driver.convertor.BeanConvert;
import com.bocloud.cmp.model.SnapshotModel;
import com.google.common.collect.Lists;

public class ConvertSnapshots implements BeanConvert<SnapshotModel, VolumeSnapshot> {

    @Override
    public List<SnapshotModel> convertList(List<? extends VolumeSnapshot> snapshots) {
        List<SnapshotModel> models = Lists.newArrayList();
        for (VolumeSnapshot snapshot : snapshots) {
            models.add(convertModel(snapshot));
        }
        return models;
    }

    @Override
    public SnapshotModel convertModel(VolumeSnapshot snapshot) {
        if (null == snapshot) {
            return null;
        }
        SnapshotModel model = new SnapshotModel();
        model.setGmtCreate(snapshot.getCreated());
        model.setName(snapshot.getName());
        model.setSize(snapshot.getSize());
        model.setSnapshotId(snapshot.getId());
        model.setVolumeId(snapshot.getVolumeId());
        if ("CREATING" == snapshot.getStatus().name()) {
            model.setStatus("BUILDING");
        } else {
            model.setStatus(snapshot.getStatus().name());
        }
        return model;
    }
}
